# Vaccine Diplomacy

## Replicates tables in main text for observational analysis
### Note to user: ordered logit models do not report clustered standard errors, these were calculated in Stata. Please see ordered_logit.do to replicate standard errors.

source("table_function.R")

# Table 1: The effect of individuals receiving a particular vaccine on trust in the government of the country where the vaccine was developed ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1) |>
  filter(country_exp != "india")

diplomacy_wide <- read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1)

outcome_vector <- c(
  "scale" = "",
  "binary" = "_binary"
)

lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_pre_trust", outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_pre", outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_pre", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_pre", outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_pre", outcome_vector[x])
    ),
    treatments = c(
      "Country developed vaccine" = "know_vax_treatment", 
      "Country developed vaccine" = "know_vaccine_country_china",
      "Country developed vaccine" = "know_vaccine_country_russia",
      "Country developed vaccine" = "know_vaccine_country_uk",
      "Country developed vaccine" = "know_vaccine_country_us"
    ),
    trust_covariates = c(
      "country_baseline_trust",
      "trust_china_baseline",
      "trust_russia_baseline",
      "trust_uk_baseline",
      "trust_biden_baseline"
    ),
    fixed_effects_name = "rollout_fe",
    table_name = paste0("main_results_observational_", names(outcome_vector[x]))
  )
)

# Table 2: The effect of receiving a particular vaccine on an individual’s ranking of the countries that developed most vaccines distributed in their country ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1) |>
  filter(country_exp != "india")

diplomacy_wide <- read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1)

table_function(
  data_frames = list(
    diplomacy_long,
    diplomacy_wide,
    diplomacy_wide,
    diplomacy_wide,
    diplomacy_wide
  ),
  outcomes = c(
    "Reversed prior (Pooled)"        = "rev_rank_prior",
    "Reversed prior (China)"         = "rev_prior_beliefs_china",
    "Reversed prior (Russia)"        = "rev_prior_beliefs_russia",
    "Reversed prior (UK)"            = "rev_prior_beliefs_uk",
    "Reversed prior (US)"            = "rev_prior_beliefs_us"
  ),
  treatments = c(
    "Country developed vaccine" = "know_vax_treatment", 
    "Country developed vaccine" = "know_vaccine_country_china",
    "Country developed vaccine" = "know_vaccine_country_russia",
    "Country developed vaccine" = "know_vaccine_country_uk",
    "Country developed vaccine" = "know_vaccine_country_us"
  ),
  trust_covariates = c(
    "country_baseline_trust",
    "trust_china_baseline",
    "trust_russia_baseline",
    "trust_uk_baseline",
    "trust_biden_baseline"
  ),
  fixed_effects_name = "rollout_fe",
  table_name = paste0("rank_results_observational")
)

# Table 3: The pooled effect of individuals receiving a particular vaccine on the perceived motivation of government of the country where the vaccine was developed for distributing vaccines ----

table_function(
  data_frames = list(
    diplomacy_long,
    diplomacy_long,
    diplomacy_long,
    diplomacy_long,
    diplomacy_long
  ),
  outcomes = c(
    "Stop COVID-19 Spread"          = "country_post_mechanisms_stopcovid",
    "Help respondent country"       = "country_post_mechanisms_help",
    "Increase support for sender"   = "country_post_mechanisms_support",
    "Increase dependence on sender" = "country_post_mechanisms_dependence",
    "Obtain economic profits"       = "country_post_mechanisms_economics"
  ), 
  treatments = c(
    "Country developed vaccine" = "know_vax_treatment", 
    "Country developed vaccine" = "know_vax_treatment",
    "Country developed vaccine" = "know_vax_treatment",
    "Country developed vaccine" = "know_vax_treatment",
    "Country developed vaccine" = "know_vax_treatment"
  ),
  trust_covariates = c(
    "country_baseline_trust",
    "country_baseline_trust",
    "country_baseline_trust",
    "country_baseline_trust",
    "country_baseline_trust"
  ),
  fixed_effects_name = "rollout_fe",
  table_name = "mechanism_effects_observational"
)